import React,{useEffect,useState} from 'react'
import store from '../store'
import {incrementAction} from '../store/actions/counterAction'
export default function Counter() {
  console.log('store',store);
  const [a,setA]=useState()
  useEffect(()=>{
    store.subscribe(()=>{
        console.log('------监听到了数据的变化--------');
        console.log('state',store.getState());
        setA({})//为了让组件执行一次更新
    })
  })    
  /*
    将store仓库中state的值进行+1操作
    使用store中的dispatch方法来发送action通知对象
  */
  const increment=()=>{
    console.log('aa',incrementAction);
    store.dispatch(incrementAction)
   
  }

  return (
    <div>
        <h1>reudx计数器案例</h1>
        <h2>{store.getState()}</h2>
        <button onClick={increment}>+</button>
    </div>
  )
}
